package com.study.java8new;

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * @author study
 * @version 1.0
 * @date 2020/6/21 11:01
 */
public class TesLambda {
    /**
     * 匿名内部类
     */
    @Test
    public void test1() {
        new Comparator<Integer>() {

            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(01, 02);
            }
        };
    }

    //lambda 表达式
    public void test2() {
        Comparator<Integer> com = (x, y) -> Integer.compare(x, y);
    }

    //集合
    List<Employee> employees = Arrays.asList(
            new Employee(1, "张三", 18, 5999),
            new Employee(2, "2张三", 20, 6000),
            new Employee(3, "3张三", 36, 7500),
            new Employee(4, "4张三", 37, 7600),
            new Employee(5, "5张三", 22, 10000),
            new Employee(6, "6张三", 29, 12000)

    );

    //提取年龄大于35 的员工
    @Test
    public void getEmp() {
        employees.stream().filter(e -> e.getSalary() > 6000).forEach(System.out::println);

        employees.stream().map(employee -> {
            return employee.getName();
        }).forEach(System.out::println);
    }
}
